package com.dmap.analysispoint.controller.rpc;

import com.dmap.analysispoint.constants.BurialPointConstant;
import com.dmap.analysispoint.service.UncertaintyInfoAnalysisService;
import com.dmap.base.send.email.MailService;
import com.dmap.base.vo.BaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.mail.MessagingException;

/**
 * \* @author:zhouhao
 * \* Date:31/05/2018
 * \* Description:
 * \*
 */
@Api(value = "没有匹配到companyId的埋点信息再处理", description = "background/没有匹配到companyId的埋点信息再处理")
@Controller
@RequestMapping(value = "/background/dmap-analysis-point-server/v2/")

public class UncertaintyInfoAnalysisController {

    @Value("${spring.profiles.active}")
    private String environment;

    @Resource
    private UncertaintyInfoAnalysisService uncertaintyInfoAnalysisService;

    private static Logger logger = LoggerFactory.getLogger(UncertaintyInfoAnalysisController.class);

    @ResponseBody
    @ApiOperation(value = "新增帐号数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "addUserInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo addUserInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.addUserInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息(新增帐号信息)定时自动分析再处理定时任务成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息(新增帐号信息)定时自动分析再处理定时任务 MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息(新增帐号信息)定时自动分析再处理定时任务 error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息(新增帐号信息)定时自动分析再处理定时任务 MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "新增手机数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "addPhoneInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo addPhoneInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.addPhoneInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增手机信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增手机信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增手机信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增手机信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "新增设备数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "addEquipmentInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo addEquipmentInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.addEquipmentInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增设备信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增设备信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增设备信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增设备信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "按天小时活跃帐号数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "activeUserHourInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo activeUserHourInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.activeUserHourInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃帐号信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃帐号信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃帐号信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃帐号信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "按天天活跃帐号数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "activeUserDayInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo activeUserDayInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.activeUserDayInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃帐号信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃帐号信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃帐号信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃帐号信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "按天小时活跃手机数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "activePhoneHourInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo activePhoneHourInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.activePhoneHourInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃手机信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃手机信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃手机信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃手机信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "按天天活跃手机数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "activePhoneDayInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo activePhoneDayInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.activePhoneDayInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃手机信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃手机信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃手机信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃手机信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "按天小时活跃设备数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "activeEquipmentHourInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo activeEquipmentHourInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.activeEquipmentHourInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃设备信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃设备信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃设备信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(小时活跃设备信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "按天天活跃设备数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "activeEquipmentDayInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo activeEquipmentDayInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.activeEquipmentDayInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃设备信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃设备信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃设备信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(天活跃设备信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "新增APP版本数据再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "appVersionInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo appVersionInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.appVersionInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增APP版本信息) 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增APP版本信息) MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增APP版本信息) error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的埋点信息定时自动分析再处理(新增APP版本信息) MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "数据看板预处理信息再处理",
            notes = "1.返回处理记录的条数")
    @RequestMapping(value = "addAndActivePhoneInfoAgainAnalysis", method = RequestMethod.GET)
    public BaseVo addAndActivePhoneInfoAgainAnalysis() {
        BaseVo baseVo = new BaseVo();
        int success = 0;
        try {
            success = uncertaintyInfoAnalysisService.addAndActivePhoneInfoAgainAnalysis();
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的数据看板预处理信息再处理 成功");
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的数据看板预处理信息再处理 MailService.sendMail error:  {}", me);
            }
        } catch (Exception e) {
            try {
                MailService.sendMail(BurialPointConstant.EMAIL_ADDRESS, BurialPointConstant.EMAIL_SUBJECT +" — "+ "环境:" + environment, "按天对没有匹配到companyId的数据看板预处理信息再处理 error: " + e);
            } catch (MessagingException me) {
                logger.error("按天对没有匹配到companyId的数据看板预处理信息再处理 MailService.sendMail error:  {}", me);
            }
        }
        baseVo.setData(success);
        return baseVo;
    }
}
